#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], c[N], d[N]; // c是a的差分数组，d是b的差分数组

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i] >> b[i];
  //   a[0] = b[0] = a[n + 1] = b[n + 1] = 0;
  int ans = 0; // 用来记录我们所需要的最小的操作的次数
  for (int i = 1; i <= n + 1; i++) {
    c[i] = a[i] - a[i - 1];
    d[i] = b[i] - b[i - 1];
  }
  for (int i = 1; i <= n + 1; i++) {
    if (c[i] >= d[i]) {
      ans += c[i] - d[i];
    }
  }
  cout << ans;
  return 0;
}
